home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / cxref_1_4a.lha / install.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1997-12-07  |  2KB  |  75 lines

  1. #!/bin/sh
  2. #
  3. # Installation script for Unices without a BSD style install (e.g. HP-UX).
  4. #
  5. # Written by Andrew M. Bishop
  6. #
  7. # This file Copyright 1995,96,97 Andrew M. Bishop
  8. # It may be distributed under the GNU Public License, version 2, or
  9. # any higher version.  See section COPYING of the GNU Public license
  10. # for conditions under which this file may be redistributed.
  11. #
  12.  
  13. if [ $# = "0" ]; then
  14.     echo "A simple installation script"
  15.     echo "usage: install.sh -d dir"
  16.     echo "       install.sh [-c] [-m mode] [-g group] [-o owner] file destination"
  17.     exit 1
  18. fi
  19.  
  20. if [ $1 = "-d" ]; then
  21.  
  22.     if [ "x$2" = "x" ]; then
  23.         echo "Directory not specified"
  24.         exit 1
  25.     fi
  26.  
  27.     dir=''
  28.     dirs=`echo $2 | sed 's%/% %g'`
  29.     for d in $dirs; do
  30.         dir="$dir/$d";
  31.         [ -d $dir ] || mkdir $dir
  32.     done
  33.  
  34. else
  35.  
  36.     mode=
  37.     owner=
  38.     group=
  39.  
  40.     while [ ! $# = 0 ]; do
  41.  
  42.         case $1 in
  43.  
  44.             -c) ;;
  45.             -m) shift; mode=$1;;
  46.             -o) shift; owner=$1;;
  47.             -g) shift; group=$1;;
  48.             -*) echo "Unrecognised option $1"; exit 1;;
  49.  
  50.             *)  src=$1; shift; dst=$1;;
  51.  
  52.         esac
  53.         shift
  54.     done
  55.  
  56.     if [ "x$src" = "x" -o "x$dst" = "x" ]; then
  57.         echo "Source and destination not specified"
  58.         exit 1
  59.     fi
  60.  
  61.     [ -d $dst ] && dst="$dst/$src"
  62.  
  63.     if cp $src $dst; then
  64.         [ $mode  ] && chmod $mode  $dst
  65.         [ $group ] && chgrp $group $dst
  66.         [ $owner ] && chown $owner $dst
  67.     else
  68.         echo Copy of $src to $dst failed
  69.         exit 1
  70.     fi
  71.  
  72. fi
  73.  
  74. exit 0
  75.